#include <stdio.h>
#include "../include/thread.h"
#include "../include/semaphore.h"

using namespace mix;

Semaphore s;

void f1() {
    for ( int i = 0; i < 10;++i) { 
        s.wait();
        printf( "waited %d.\n", i);
    }
}

void f2() {
    for( int i = 0; i < 10; ++i) {
        s.post();
        Thread::sleep( 500);
    }
}

int main() {
    if ( !s.init()) {
        printf( "init error.\n");
        return 0;
    }

    Thread t1( f1);
    Thread t2( f2);

    t1.start();
    t2.start();

    t1.join();
    t2.join();

    return 0;
}
